<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <div style="display: flex;align-items: center; justify-content: space-between;">
     <div class="search" style="display: flex; align-items: center;">
      <!-- 下拉选择字段 -->
      <el-select v-model="data.searchField" placeholder="请选择查询类型" style="width: 150px; margin-right: 10px">
        <el-option label="批次号" value="delv_bchno" />
        <el-option label="订单号" value="from_bill_sc" />
        <el-option label="客户名称" value="fixmedins_hilist_name" />
      </el-select>

      <!-- 输入框 -->
      <el-input
        clearable
        @clear="load"
        v-model="data.searchValue"
        style="width: 250px; margin-right: 15px"
        placeholder="请输入查询内容"
        :prefix-icon="Search"
      ></el-input>

      <!-- 日期时间范围选择器 -->
      <el-date-picker
        v-model="currentDate"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        style="width: 350px; margin-right: 15px"
        format="YYYY-MM-DD"
        value-format="YYYY-MM-DD"
        :clearable="false"
      />


    <!-- 查询按钮 -->
    <!-- <el-button type="primary" @click="load">查 询</el-button>
  </div> -->

      <!-- 查询按钮 -->
      <el-button type="primary" @click="load">查 询</el-button>
      <el-button type="success" @click="data.downloadVisible = true">批量下载</el-button>
    </div>
    <!-- 重传和下载 -->
     <div class="resend" style="margin-right: 100px;">
      <el-button type="warning" @click="handleTransmit">重传列表</el-button>
      <el-button type="success" @click="handleDownload">下载</el-button>
      <el-button type="danger" @click="deleteBatch">批量删除</el-button>
     </div>
  </div>
      <!-- 详情显示 -->
          <el-dialog
            title="详情"
            v-model="data.detailVisible"
            width="80%"
            destroy-on-close
            v-loading="detailLoading"
            element-loading-text="加载中..."
          >
            <div class="search">
              <el-input clearable @clear="closeDetail" v-model="data.list.name" style="width: 300px; margin-right: 5px"  placeholder="请输入追溯码查询" :prefix-icon="Search"></el-input>
              <el-button type="primary" style="margin-left: 15px;" @click="viewDetail">查 询</el-button>
            </div>

            <!-- 表格容器，设置固定高度和滚动 -->
            <div class="table-container">
              <el-table
                :data="data.list.list"
                border
                style="width: 100%"
                :header-cell-style="{
                  color: '#333',
                  backgroundColor: '#eaf4ff',
                  height: '20px'  // 表头固定高度
                }"
                :row-style="{ height: '20px' }"
                :cell-style="{ padding: '5px 0' }"
              >
                <el-table-column prop="sscPickingCartonDetailId" label="出库明细id" width="100"/>
                <el-table-column prop="invOwnerName" label="库存拥有者" :resizable="true" width="200"/>
                <el-table-column prop="clientName" label="客户名称" :resizable="true" width="180"/>
                <el-table-column prop="saleOrgName" label="销售部门名称" :resizable="true" width="120"/>
                <el-table-column prop="warehouseName" label="仓库名称" :resizable="true" width="100"/>
                <el-table-column prop="createName" label="开票员" :resizable="true" width="100"/>
                <el-table-column prop="createDate" label="开单日期" :resizable="true" width="180"/>
                <el-table-column prop="cartonTypeName" label="出库形式" :resizable="true" width="80"/>
                <el-table-column prop="cartonCode" label="包装编码" :resizable="true" width="80"/>
                <el-table-column prop="dacode" label="追溯码" :resizable="true" width="200"/>
                <el-table-column prop="fromBillSc" label="订单号码" :resizable="true" width="200"/>
                <el-table-column prop="goodsOpcode" label="商品编码" :resizable="true" width="100"/>
                <el-table-column prop="goodsName" label="商品名称" :resizable="true" min-width="150"/>
                <el-table-column prop="goodsDesc" label="商品规格" :resizable="true" min-width="150"/>
                <el-table-column prop="productLocation" label="生产厂家" :resizable="true" width="150"/>
                <el-table-column prop="goodsPackage" label="追溯码包装数" :resizable="true" min-width="120"/>
                <el-table-column prop="cartonQty" label="出库数量" :resizable="true" min-width="100"/>
                <el-table-column prop="packTypeName" label="追溯码类型" :resizable="true" min-width="120"/>
                <el-table-column prop="packageNum" label="包装数量" :resizable="true" min-width="100"/>
                <el-table-column prop="pkgRatio" label="包装比例" :resizable="true" min-width="100"/>
                <el-table-column prop="opFlagName" label="解析状态" :resizable="true" min-width="100"/>
                <el-table-column prop="impDate" label="导入日期" :resizable="true" width="180"/>
                <el-table-column prop="transDate" label="追溯码解析日期" :resizable="true" width="180"/>
                <el-table-column prop="memo" label="解析返回" :resizable="true" min-width="150"/>
                <el-table-column prop="execFlagName" label="医保状态" :resizable="true" min-width="100"/>
                <el-table-column prop="execDate" label="医保传输时间" :resizable="true" width="180"/>
                <el-table-column prop="execMsg" label="医保返回" :resizable="true" min-width="150"/>
                <el-table-column prop="invChgTime" label="出库日期" :resizable="true" width="180"/>
                <el-table-column prop="delvBchno" label="批次流水号" :resizable="true" min-width="120"/>
                <el-table-column prop="authDocno" label="批准文号" :resizable="true" min-width="150"/>
                <el-table-column prop="medListCodg" label="国家医保代码" :resizable="true" min-width="150"/>
                <el-table-column prop="lotNo" label="商品批号" :resizable="true" min-width="120"/>
              </el-table>
            </div>

            <!-- 分页 -->
            <div style="margin-top: 20px; text-align: right">
              <el-pagination
                v-model:current-page="data.list.pageNum"
                v-model:page-size="data.list.pageSize"
                :total="data.list.total"
                layout="total, sizes, prev, pager, next"
                :page-sizes="[10, 20, 50]"
                @current-change="viewDetail"
                @size-change="viewDetail"
              />
            </div>
          </el-dialog>

      <!-- 重传列表显示 -->
       <el-dialog title="重传列表" v-model="data.resendVisible" width="1200" destroy-on-close >
         <div style="margin: 30px; display: flex; align-items: center; gap: 15px;">
          <el-button type="danger" @click="handleResendBatch">批量重传</el-button>

          <!-- 搜索框 -->
          <el-input
            v-model="data.resend.searchValue"
            placeholder="请输入客户名称"
            clearable
            style="width: 250px"
            :prefix-icon="Search"
          />
          <el-button type="primary" @click="handleTransmit">搜索</el-button>
        </div>
        <!-- 横向滚动容器 -->
        <div style="overflow-x: auto;">
          <el-table :data="data.resend.resendData" @selection-change="handleSelectionChange" style="width: 100%" :header-cell-style="{ color: '#333', backgroundColor: '#eaf4ff' }">
          <el-table-column type="selection" width="55" />
          <el-table-column prop="fromBillSc" label="订单号" />
          <el-table-column prop="fixmedinsHilistName" label="客户名称" />
          <el-table-column prop="delvBchno" label="批次流水号" />
          <el-table-column prop="fixmedinsHilistId" label="医疗机构代码" />
          <el-table-column prop="opFlag" label="解析状态" />
          <el-table-column prop="execFlag" label="医保状态" />

          <el-table-column  label="操作" >
            <template #default="scope">
              <el-button type="text" @click="retry(scope.row)">重传</el-button>
            </template>
          </el-table-column>
        </el-table>
        </div>

        <!-- 分页 -->
        <div style="margin-top: 20px; text-align: right">
          <el-pagination
            v-model:current-page="data.resend.pageNum"
            v-model:page-size="data.resend.pageSize"
            :total="data.resend.total"
            layout="total, sizes, prev, pager, next"
            :page-sizes="[10, 20, 50]"
            @current-change="handleTransmit"
            @size-change="handleTransmit"
          />
        </div>
      </el-dialog>

      <!-- 批量下载 -->
       <el-dialog title="批量下载" v-model="data.downloadVisible" width="700" destroy-on-close >
        <!-- 日期时间范围选择器 -->
      <el-date-picker
        v-model="currentDate"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        style="width: 350px; margin: 15px"
        format="YYYY-MM-DD"
        value-format="YYYY-MM-DD"
        :clearable="false"
      />
        <!-- 输入框 -->
        <el-input
          clearable
          v-model="data.piliang.clientId"
          style="width: 300px; margin-right: 15px"
          placeholder="双击选择客户代码和名称"
          @dblclick="data.clientSetDialogVisible = true"
          :prefix-icon="Search"
        ></el-input>
        <el-input
          clearable
          v-model="data.piliang.clientName"
          style="width: 300px; margin-right: 15px"
          placeholder="双击选择客户代码和名称"
          @dblclick="data.clientSetDialogVisible = true"
          :prefix-icon="Search"
        ></el-input>
        <!-- <el-form-item label="客户名称" prop="clientName">
          <el-input v-model="policyForm.clientName" placeholder="客户名称" disabled style="width: 200px"/>
        </el-form-item> -->
         <el-button type="primary" style="margin-top: 20px;" @click="resetClientCodeList" >下载</el-button>


      </el-dialog>

      <!-- 客户选择 -->
      <el-dialog title="选择客户" v-model="data.clientSetDialogVisible" width="500" destroy-on-close>
        <!-- 输入框 -->
         <div style="display: flex;align-items: center; ">
          <el-input
          clearable
          v-model="data.searchClient"
          style="width: 300px; margin-right: 15px"
          placeholder="请输入客户名称"
          :prefix-icon="Search"
        ></el-input>
          <el-button type="primary" @click="handleClientSetConfirm">查询</el-button>
         </div>
         <el-table :data="data.clientSet" @row-click="selectClient"> style="width: 100%; margin-top: 10px;" :header-cell-style="{ color: '#333', backgroundColor: '#eaf4ff' }">
            <el-table-column prop="fixmedinsHilistId" label="客户ID" width="120" />
            <el-table-column prop="clientName" label="客户名称" />
         </el-table>

      </el-dialog>

    <!-- 内容显示区域 -->
    <div class="content">
      <el-table
        :data="data.tableData"
        @selection-change="handleSelectionChange"
        style="width: 100%"
        :header-cell-style="{ color: '#333', backgroundColor: '#eaf4ff' }"
      >
        <el-table-column type="selection" width="55" />

        <el-table-column prop="fromBillSc" label="订单号" width="150px"/>
        <el-table-column prop="fixmedinsHilistName" label="客户名称" width="320" />
        <el-table-column prop="fixmedinsHilistId" label="医疗机构代码" />
        <el-table-column prop="delvBchno" label="批次流水号" />
        <el-table-column prop="execFlag" label="医保状态" />

        <el-table-column label="详情">
          <template #default="scope">
            <el-button type="text" @click="viewDetail(scope.row)">
              <el-icon style="font-size: 25px;"><Search /></el-icon>
            </el-button>
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <template #default="scope">
            <template v-if="scope.row.execFlag === '传输成功'">
              <el-button type="text" @click="del(scope.row,'0')">删除重传</el-button>
              <el-button type="text" @click="del(scope.row,'1')">彻底删除</el-button>
            </template>
            <template v-else-if="scope.row.execFlag === '待重传'">
              <el-button type="warning" @click="retry(scope.row)">待重传</el-button>
            </template>
          </template>
        </el-table-column>

      </el-table>
    </div>
    <!-- 分页 -->
     <div class="card">
      <el-pagination
          v-model:current-page="data.pageNum"
          v-model:page-size="data.pageSize"
          layout="total,sizes, prev, pager, next"
          :total="data.total"
          :page-sizes="[20, 40, 80]"
          @current-change="load"
          @size-change="load"
      />
    </div>
</template>
<script setup>
import {Search } from "@element-plus/icons-vue";
import { reactive,ref,nextTick,onMounted, onBeforeUnmount} from 'vue';
import request from '../../utils/request.js';
import { ElMessage,ElMessageBox } from 'element-plus';
import {currentDate} from '../../utils/time.js';
import { ElLoading } from 'element-plus';


// 多条数据进行删除
const multipleSelection = ref([]);
const detailLoading = ref(false);

let loadingInstance = null;
// const search = ref('');
const data = reactive({
  clientSet:[],
  downloadVisible: false,
  clientSetDialogVisible: false,
  searchClient:'',
  searchValue: '',
  searchField:'delv_bchno',
  pageNum: 1,
  pageSize: 20,
  total: 0,
  detailVisible: false,
  resendVisible: false,
  tableData: [],
  resend:{
    resendData:[],
    pageNum: 1,
    pageSize: 20,
    total: 1,
    name:'',
    searchValue:''

  },
  list:{
    list: [],
    pageNum: 1,
    pageSize: 20,
    total: 1,
    name:'',
    delvBchno:'',
  },
  piliang:{
    medListCodg:'',
    clientId:'',
    clientName:''
  }
});

const load = () => {
  const loadingInstance = ElLoading.service({
    lock: true,
    text: '数据加载中，请稍候...',
    background: 'rgba(255, 255, 255, 0.7)',
  });

  request.get('/user/getPickingCartonDetails', {
    params: {
      pageNum: data.pageNum,
      pageSize: data.pageSize,
      field: data.searchField,
      name: data.searchValue,
      startDate: currentDate.value[0],
      endDate: currentDate.value[1]
    }
  })
  .then((res) => {
    data.tableData = res.data.list;
    data.total = res.data.total;
  })
  .catch((err) => {
    console.error('请求失败', err);
    ElMessage.error('加载失败，请稍后再试');
  })
  .finally(() => {
    loadingInstance.close();
  });
};

// load();

// 批量下载
const resetClientCodeList = async () => {
  if (data.piliang.clientId === '' || data.piliang.clientName === '') {
    ElMessage.error('请输入信息')
    return
  }

  let loading = null
  try {
    // 开启遮罩层
    loading = ElLoading.service({
      lock: true,
      text: '正在下载，请稍候...',
      background: 'rgba(255, 255, 255, 0.7)',
    })

    // 构建请求参数
    const requestData = {
      invOwner: JSON.parse(localStorage.getItem('currentOwnerId')),
      fromBillSc: '',
      clientId: '',
      fixmedinsHilistName: data.piliang.clientName,
      delvBchno: '',
      opFlag: '',
      execFlag: '',
      fixmedinsHilistId: data.piliang.clientId,
      startDate: currentDate.value[0],
      endDate: currentDate.value[1],
    }

    // 发送请求
    const res = await request.post('/user/exportExcel', requestData, {
      responseType: 'blob',
    })

    // 文件名处理
    const disposition = res.headers?.['content-disposition']
    let filename = `${data.piliang.clientName}.xlsx`
    if (disposition) {
      const match = disposition.match(/filename\*=UTF-8''(.+)/)
      if (match) {
        filename = decodeURIComponent(match[1])
      }
    }

    // 创建 blob 下载
    const blob = new Blob([res.data], {
      type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    })
    const link = document.createElement('a')
    const url = window.URL.createObjectURL(blob)
    link.href = url
    link.download = filename
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
    window.URL.revokeObjectURL(url)

    console.log(`下载完成`)
    ElMessage.success('下载完成')
  } catch (err) {
    console.error(`下载失败`, err)
    ElMessage.error(`下载失败`)
    ElMessage.error(err.message || '下载失败')
  } finally {
    // 关闭遮罩层
    if (loading) loading.close()
  }
}


const selectClient = (row) => {
  data.piliang.clientId = row.fixmedinsHilistId
  data.piliang.clientName = row.clientName
  data.clientSetDialogVisible = false
  console.log('选中行:', row);
}

// 客户查询
const handleClientSetConfirm=()=>{
  request.get('/user/getClient', {
    params: {
      name: data.searchClient
    }
  }).then((res)=>{
    data.clientSet = res.data
  })
}

// 多选
const handleSelectionChange = (selection) => {
  console.log('选中行:', selection);
  multipleSelection.value = selection;
};


const viewDetail = (row) => {
  let delvBchno = '';
  if (row?.delvBchno === undefined) {
    delvBchno = data.list?.delvBchno;
  } else {
    delvBchno = row.delvBchno;
    data.list.delvBchno = delvBchno;
  }

  data.detailVisible = true;

  // 等待 DOM 渲染完 el-dialog 后再挂 loading
  nextTick(() => {
    loadingInstance = ElLoading.service({
      target: '.el-dialog__body',
      text: '加载中...'
    });
  });

  request.post('/user/getDetailInfo', {
    delvBchno: delvBchno,
    pageNum: data.list.pageNum,
    pageSize: data.list.pageSize,
    name: data.list.name
  }).then((res) => {
    data.list.list = res.data.list;
    data.list.total = res.data.total;
  }).catch((err) => {
    ElMessage.error('详情加载失败');
    console.error(err);
  }).finally(() => {
    if (loadingInstance) loadingInstance.close();
  });
};



const closeDetail=()=>{
    data.detailVisible = true;
      // 等待 DOM 渲染完 el-dialog 后再挂 loading
  nextTick(() => {
    loadingInstance = ElLoading.service({
      target: '.el-dialog__body',
      text: '加载中...'
    });
  });

  request.post('/user/getDetailInfo', {
    delvBchno: data.list.delvBchno,
    pageNum: data.list.pageNum,
    pageSize: data.list.pageSize,
    name: ''
  })
  .then((res) => {
    console.log('res', res);
    data.list.list = res.data.list;
    data.list.total = res.data.total;
  })
  .catch((err) => {
    console.error('请求失败', err);
  }).finally(() => {
    if (loadingInstance) loadingInstance.close();
  });
}

// 重传列表
const handleTransmit = () => {
  data.resendVisible = true;
  nextTick(() => {
    loadingInstance = ElLoading.service({
      target: '.el-dialog__body',
      text: '加载中...'
    });
  });
  // 获取待重传数据
  request.get('/user/getResend', {
    params: {
      pageNum: data.resend.pageNum,
      pageSize: data.resend.pageSize,
      name: data.resend.searchValue
    }
  })
  .then((res) => {
    console.log('res', res);
    data.resend.resendData = res.data.list;
    data.resend.total = res.data.total;
  })
  .catch((err) => {
    console.error('请求失败', err);
  }).finally(() => {
    if (loadingInstance) loadingInstance.close();
  });
};
const handleDownload = async () => {
  if (multipleSelection.value.length === 0) {
    ElMessage.warning('请先选择要下载的记录');
    return;
  }

  // 开启全屏 Loading 遮罩
  const loadingInstance = ElLoading.service({
    fullscreen: true,
    text: '正在下载文件，请稍候...',
  });

  let hasError = false;

  for (let i = 0; i < multipleSelection.value.length; i++) {
    const item = multipleSelection.value[i];

    const requestData = {
      invOwner: item.invOwner || '',
      fromBillSc: item.fromBillSc || '',
      clientId: item.clientId,
      fixmedinsHilistName: item.fixmedinsHilistName,
      delvBchno: item.delvBchno,
      opFlag: item.opFlag,
      execFlag: item.execFlag,
      fixmedinsHilistId: item.fixmedinsHilistId,
      startDate: '',
      endDate: ''
    };

    try {
      const res = await request.post('/user/exportExcel', requestData, {
        responseType: 'blob'
      });

      const disposition = res.headers?.['content-disposition'];
      let filename = `${item.delvBchno}.xlsx`;
      if (disposition) {
        const match = disposition.match(/filename\*=UTF-8''(.+)/);
        if (match) {
          filename = decodeURIComponent(match[1]);
        }
      }

      const blob = new Blob([res.data], {
        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
      });

      const link = document.createElement('a');
      link.href = window.URL.createObjectURL(blob);
      link.download = filename;
      link.click();
      window.URL.revokeObjectURL(link.href);

      console.log(`第 ${i + 1} 个文件下载完成`);
    } catch (err) {
      hasError = true;
      console.error(`第 ${i + 1} 个下载失败`, err);
      ElMessage.error(`第 ${i + 1} 个文件下载失败`);
    }

    await new Promise(resolve => setTimeout(resolve, 800));
  }

  // 关闭 Loading 遮罩
  loadingInstance.close();

  if (!hasError) {
    ElMessage.success(`全部文件下载完成`);
  } else {
    ElMessage.warning(`部分文件下载失败`);
  }
};

const del = (row, type) => {
  console.log('row',row);

   ElMessageBox.confirm("是否删除该条记录？",'删除确认',{type:'warning'}).then((res)=>{
     if (res) {
      const loadingInstance = ElLoading.service({
          lock: true,
          text: '数据加载中，请稍候...',
          background: 'rgba(255, 255, 255, 0.7)',
        });
       // 调用删除接口
       request.post('/user/delById', {
        type: type,
         invOwner: row.invOwner,
         fromBillSc: row.fromBillSc,
         clientId: row.clientId,
         fixmedinsHilistName: row.fixmedinsHilistName,
         delvBchno: row.delvBchno,
         opFlag: row.opFlag,
         execFlag: row.execFlag,
         fixmedinsHilistId: row.fixmedinsHilistId
       }).then((res) => {
        if (res.code === 200) {
          console.log('res',res);
          ElMessage.success('删除成功');
          load();
        }
         else {
          ElMessage.error('删除失败');
        }
       }).catch((err) => {
         console.error('请求失败', err);
       }).finally(() => {
         if (loadingInstance) loadingInstance.close();
       });
     }
   })

};

const deleteBatch = () => {
  console.log('multipleSelection.value',multipleSelection.value)
  console.log('multipleSelection.value.length',multipleSelection.value.length)
  if (multipleSelection.value.length === 0) {
    ElMessage.warning('请先选择要删除的记录');
    return;
  }
  ElMessageBox.confirm("是否批量删除选中的记录？", "批量删除确认", {
    type: 'warning'
  }).then(() => {
    console.log('multipleSelection.value',multipleSelection.value)
    console.log('111',111)
     const loadingInstance = ElLoading.service({
          lock: true,
          text: '数据加载中，数据量有些大，请稍等几分钟...',
          background: 'rgba(255, 255, 255, 0.7)',
        });
    request.post('/user/deleteBatch', multipleSelection.value.map(item => ({
      invOwner: item.invOwner,
      fromBillSc: item.fromBillSc,
      clientId: item.clientId,
      fixmedinsHilistName: item.fixmedinsHilistName,
      delvBchno: item.delvBchno,
      opFlag: item.opFlag,
      execFlag: item.execFlag,
      fixmedinsHilistId: item.fixmedinsHilistId

    }))).then((res)=>{
      console.log('res',res)
      if (res.code === 200) {
        ElMessage.success('批量删除成功');
        load();
      } else {
        ElMessage.error('批量删除失败，请稍后再试');
      }

    }).catch((err)=>{
      console.error('请求失败', err);
      ElMessage.error('批量删除失败，请稍后再试');
    }).finally(() => {
      if (loadingInstance) loadingInstance.close();
    });
  })
};

// 重传

const retry = (row) => {

  ElMessageBox.confirm("是否重传该条记录？", '重传确认', { type: 'warning' }).then((res) => {
    if (res) {
      const loadingInstance = ElLoading.service({
        lock: true,
        text: '数据加载中，数据量有些大，请稍等几分钟...',
        background: 'rgba(255, 255, 255, 0.7)',
      });
        request.post('/user/resend',{
        inv: row.invOwner,
        delvBchno: '',
        fromBillSc: row.fromBillSc
      }).then((res)=>{
        console.log('res',res)
        if (res.code === 200) {
          ElMessage.success('重传成功');
          handleTransmit();
          load();
        } else {
          ElMessage.error('重传失败，请稍后再试');
        }

      }).catch((err)=>{
        console.error('请求失败', err);
        ElMessage.error('重传失败，请稍后再试');
      }).finally(() => {
        if (loadingInstance) loadingInstance.close();
      });
    }
  });
}

const handleResendBatch = () => {
  console.log('multipleSelection.value',multipleSelection.value)
  if (multipleSelection.value.length === 0) {
    ElMessage.warning('请先选择要重传的记录');
    return;
  }
  ElMessageBox.confirm("是否批量重传选中的记录？", "批量重传确认", {
    type: 'warning'
  }).then(() => {
  const loadingInstance = ElLoading.service({
        lock: true,
        text: '数据加载中，数据量有些大，请稍等几分钟...',
        background: 'rgba(255, 255, 255, 0.7)',
      });
    console.log('multipleSelection.value', multipleSelection.value);
    request.post('/user/resendBatch', multipleSelection.value.map(item => ({
      inv: item.invOwner,
      delvBchno: '',
      fromBillSc: item.fromBillSc
    }))).then((res)=>{
      console.log('res', res);
      if (res.code === 200) {
        ElMessage.success('批量重传成功');
        handleTransmit();
        load();
      } else {
        ElMessage.error('批量重传失败，请稍后再试');
      }
    }).finally(() => {
      if (loadingInstance) loadingInstance.close();
    })
  });
};

const mykey = ref(null)

const handleStorageChange = (e) => {
  if (e.key === 'currentOwnerId') {
    mykey.value = e.newValue
    load()
    console.log(JSON.parse(e.newValue))
    console.log('本地存储值发生变化：', e.newValue)
  }
}

onMounted(() => {
  window.addEventListener('setItemEvent', handleStorageChange)
})

onBeforeUnmount(() => {
  window.removeEventListener('setItemEvent', handleStorageChange)
})
</script>

<style scoped lang="css">
.search{
  margin-bottom: 25px
}

.content{
  margin-bottom: 25px
}

.table-container {
  height: 500px;
  overflow: auto;
  border: 1px solid #ebeef5;
}

.el-table::before {
  height: 0;
}

.el-table__body tr,
.el-table__body td {
  height: 20px;
  padding: 5px 0;
}

.el-table__header-wrapper {
  position: sticky;
  top: 0;
  z-index: 2;
}
</style>
